package com.zixuan.sina.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

public class DateComputeUtils {
    /**
     *
     * @param end 被减时间
     * @param start 减去时间 现在时间
     * @return
     */
    public static String between(Date end, Date start) {

        String timeStr = "";
        long time = DateUtil.between(start, end, DateUnit.WEEK, false);
        timeStr = time + "周前";
        if (time <= 0) {
            time = DateUtil.between(start, end, DateUnit.DAY, false);
            timeStr = time + "天前";
            if (time <= 0) {
                time = DateUtil.between(start, end, DateUnit.HOUR, false);
                timeStr = time + "小时前";
                if (time <= 0) {
                    time = DateUtil.between(start, end, DateUnit.MINUTE, false);
                    timeStr = time + "分钟前";
                    if (time <= 0) {
                        time = DateUtil.between(start, end, DateUnit.SECOND, false);
                        timeStr = time + "秒前";
                        if (time <= 0) {
                            timeStr = "刚刚";
                        }
                    }
                }
            }
        }else {
            //年
            if(time/48>0){
                timeStr=(time/48)+"年前";
            }else if(time/4>0){
                //月
                timeStr=(time/4)+"月前";
            }

        }
        return timeStr;
    }

//    public static void main(String[] args) {
//        DateTime date = DateUtil.date();
//        System.out.println(date);
//        DateTime date1 = DateUtil.date(new Date());
//        date1 = DateUtil.offsetHour(date1,-10);//-10个小时
//        System.out.println(date1);
//        String between = DateComputeUtils.between(date, date1);
//        System.out.println(between);
//
//    }
}
